package com.example.ivory.accountbook.packetActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.ivory.accountbook.R;

import java.util.HashMap;
import java.util.Map;

import de.greenrobot.event.EventBus;

/**
 * Created by 王如梦 on 2016/8/29.
 */
public class inaddActivity extends Activity {
    //界面按钮
    Button buttonBackAdds;
    Button buttonAddAccounts;
    TextView txtPacketTypes;
    EditText editAccountNames;
    EditText editAccountBalances;

    //钱包的数据
    Map<String,Object> packet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inaddpacket);

        //绑定界面上的控件
        buttonBackAdds= (Button) findViewById(R.id.buttonBackAdd);
        buttonAddAccounts= (Button) findViewById(R.id.buttonAddAccount);
        txtPacketTypes= (TextView) findViewById(R.id.textviewPacketType);
        editAccountNames= (EditText) findViewById(R.id.editAccountName);
        editAccountBalances= (EditText) findViewById(R.id.editAccountBalance);

        //从跳转中获得数据
        Intent getintent=this.getIntent();

        String type=getintent.getStringExtra("type");
        txtPacketTypes.setText(type);

        //加入钱包的类型
        packet=new HashMap<String, Object>();
        packet.put("type",type);

        //创建返回监听
        buttonBackAdds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(inaddActivity.this,addpacketActivity.class));
                finish();
            }
        });

        //建钱包成功的监听
        buttonAddAccounts.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取钱包的名称和余额
                //并且数据传递过去
                packet.put("name",editAccountNames.getText().toString());
                packet.put("money",editAccountBalances.getText().toString());

                EventBus.getDefault().post(packet);

                //结束当前的activity
                inaddActivity.this.finish();
            }
        });
    }
}
